import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes.js'
Vue.use(VueRouter)

// 保存一个路由原型上的push和replace方法
const originPush=VueRouter.prototype.push;
const originReplace=VueRouter.prototype.replace;

//修改VueRouter原型上的push，用于解决重复跳转报错
VueRouter.prototype.push = function(location,okCallBack,errCallBack){
	if(okCallBack === undefined && errCallBack === undefined){
		return originalPush.call(this,location).catch(()=>{})
	}else{
		return originalPush.call(this,location,okCallBack,errCallBack)
	}
}
//修改VueRouter原型上的replace，用于解决重复跳转报错
VueRouter.prototype.replace = function(location,okCallBack,errCallBack){
	if(okCallBack === undefined && error === errCallBack){
		return originalReplace.call(this,location).catch(()=>{})
	}else{
		return originalReplace.call(this,location,okCallBack,errCallBack)
	}
}

const router = new Router({
    mode:'history',
    routes
})

export default router